package com.hongsen.cn.adapter;

import android.annotation.SuppressLint;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.databinding.DataBindingUtil;
import androidx.recyclerview.widget.RecyclerView;

import com.hongsen.cn.base.BaseRecyclerViewHolder;
import com.hongsen.cn.dayandmonth.R;
import com.hongsen.cn.dayandmonth.databinding.ItemHomePageBinding;
import com.hongsen.cn.listener.OnItemClickListener;

import java.util.ArrayList;
import java.util.List;

public class HomePageAdapter extends RecyclerView.Adapter<BaseRecyclerViewHolder> {
    private List<String> strings = new ArrayList<>();
    private Context mcontext;
    public OnItemClickListener mOnItemClickLitener;


    public HomePageAdapter(Context context, List<String> strings) {
        this.mcontext = context;
        this.strings = strings;

    }

    @Override
    public BaseRecyclerViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        ItemHomePageBinding binding = DataBindingUtil.inflate(LayoutInflater.from(mcontext),
                R.layout.item_home_page, parent, false);
        binding.setAdapter(this);
        return new TourViewHolder(binding);
    }


    @Override
    public void onBindViewHolder(final BaseRecyclerViewHolder holder, @SuppressLint("RecyclerView") final int position) {
        holder.bindData(strings.get(position));


        if (mOnItemClickLitener != null) {
            holder.itemView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    int pos = holder.getLayoutPosition();
                    mOnItemClickLitener.onItemClick(holder.itemView, pos);
                }
            });

            holder.itemView.setOnLongClickListener(new View.OnLongClickListener() {
                @Override
                public boolean onLongClick(View v) {
                    int pos = holder.getLayoutPosition();
                    mOnItemClickLitener.onItemLongClick(holder.itemView, pos);
                    return false;
                }
            });
        }
    }

    public void setOnItemClickLitener(OnItemClickListener mOnItemClickLitener) {
        this.mOnItemClickLitener = mOnItemClickLitener;
    }

    @Override
    public int getItemCount() {
        return strings.size();
    }

    public class TourViewHolder extends BaseRecyclerViewHolder<String> {
        ItemHomePageBinding binding;

        public TourViewHolder(ItemHomePageBinding dataBinding) {
            super(dataBinding.getRoot());
            binding = dataBinding;
        }

        @Override
        public void bindData(String data) {
            binding.setBean(data);
        }
    }

    @Override
    public int getItemViewType(int position) {
        return strings.size();
    }
    //
    //    /**
    //     * 用药单次（片/已手动录入）
    //     * 天数（最多31天已手动录入）
    //     * 频率（已手动录入）
    //     * 服用方法（已手动录入）
    //     */
    //    public Dialog useASingleDialog;
    //
    //    public void useASingle(List<String> list) {
    //        useASingleDialog = new Dialog(mcontext, R.style.MyDialog);
    //        if (useASingleDialog.isShowing()) {
    //            return;
    //        }
    //        DialogUseASingleBinding selectPatientBinding = DataBindingUtil.inflate(LayoutInflater.from(mcontext),
    //                R.layout.dialog_use_a_single, null, false);
    //        useASingleDialog.setContentView(selectPatientBinding.getRoot());
    //        Window window = useASingleDialog.getWindow();
    //        WindowManager.LayoutParams layoutParams = window.getAttributes();
    //        layoutParams.width = WindowManager.LayoutParams.MATCH_PARENT;
    //        layoutParams.height = WindowManager.LayoutParams.WRAP_CONTENT;
    //        window.setAttributes(layoutParams);
    //        //设置弹出位置
    //        window.setGravity(Gravity.BOTTOM);
    //        window.setWindowAnimations(R.style.main_menu_animStyle);
    //
    //        selectPatientBinding.rlModuleDialogDoctorSelectPatient.setLayoutManager(new GridLayoutManager(mcontext, 5));
    //        selectPatientBinding.rlModuleDialogDoctorSelectPatient.setItemAnimator(new DefaultItemAnimator());
    //        UseASingleAdapter doctorSelectPatientAdapter = new UseASingleAdapter(mcontext, list);
    //        selectPatientBinding.rlModuleDialogDoctorSelectPatient.setAdapter(doctorSelectPatientAdapter);
    //        doctorSelectPatientAdapter.setOnItemClickLitener(new OnItemClickListener() {
    //            @Override
    //            public void onItemClick(View view, int position) {
    //                useASingleDialog.dismiss();
    //                switch (type) {
    //                    case "1":
    //                        updateBean.setYf(listInfos.get(position));
    //                        notifyItemChanged(location);
    //                        break;
    //                    case "2":
    //                        updateBean.setPl(listPLSelect.get(position));
    //                        notifyItemChanged(location);
    //                        break;
    //                    case "3":
    //                        updateBean.setMcsl(Integer.valueOf(listLongly.get(position)));
    //                        notifyItemChanged(location);
    //                        break;
    //                    case "4":
    //                        updateBean.setTs(Integer.valueOf(listDays.get(position)));
    //                        notifyItemChanged(location);
    //                        break;
    //                    default:
    //                }
    //            }
    //
    //            @Override
    //            public void onItemLongClick(View view, int position) {
    //
    //            }
    //        });
    //
    //        useASingleDialog.show();
    //        selectPatientBinding.llModuleDialogDismiss.setOnClickListener(new View.OnClickListener() {
    //            @Override
    //            public void onClick(View v) {
    //                useASingleDialog.dismiss();
    //            }
    //        });
    //    }

}
